
import { createStoreBindings } from "mobx-miniprogram-bindings"
import store from "../../store/piece"
const { BASEURL } = require('../../request/config')
import prodInfoApi from '../../api/prodInfo'
import enumApi from '../../api/enum'
import orderApi from '../../api/order'
Page({
  data: {
    tsjgMap:{
      1:"来版染色",
      2:"美薄",3:"增厚/配比重",4:"偏心",5:"棱镜度"
    },
    tjObj:{
      1:"进口产品&1.67以上<含1.67>折射率",
      2:"其他",
      3:"国产1.67以上<含1.67>折射率",
      4:'国产其他'
    },

    left:null,//左眼
    right:null,//右眼
    parameter:null, //商品详情
    jjxxMap:{
      1:"全框" ,
      2:"半框" ,
      3:"无框"
    },
    payMap:{
      1:"微信支付",
      2:"云闪付",
      3:"余额支付"
    },
    baseUrl:BASEURL,
    orderMap:{
      "-1":"已取消",
      "0":"待付款",
      "1":"待发货",
      "2":"待收货",
      "3":"已完成",
      "4":"付款成功",
      "5":"待取货"
    },
    orderId:null,
    threeMonthFlag:false

  },
  onLoad(data) {
    this.setData({
      orderId:data.id
    })
      this.orderDetail(data.id)
     
  },
  onUnload() {
  },
  orderDetail(id) {
    orderApi.orderDetail(id).then((res)=>{
        let tsjg = res.tsjg
        let left =  res.left
        let right = res.right
        let threeMonthFlag =res.threeMonthFlag
        this.setData({
          tsjg,
          left,
          right,
          threeMonthFlag,
          parameter:res
        })
    })
  },
  enumSpecialProcess() {
    enumApi.enumSpecialProcess().then((res) => {
      let specialList = {}
      res.forEach(element => {
        specialList[element.id] = element.label
      });

      this.setData({
        specialList:specialList
      })
    })
  },
  enumSpecialCondition() {
    enumApi.enumSpecialCondition().then((res) => {
      let conditionList = {}
      res.forEach(element => {
        conditionList[element.id] = element.label
      });
      this.setData({
        conditionList:conditionList
      })
    })
  },
  orderBtn() {
    //下单
    if(!this.data.skuid) {
      wx.showToast({ title: '必须选择膜', icon: 'none' });
      return
    }
    
    let parameter = this.data.parameter
    let formData = this.data.formData
    
    let data = {
      eyesLength:parameter.pdTitle,//双眼瞳距
      jjxx:parameter.frameType, //镜架
      left:{
        prodId:this.data.prodId,//产品id
        skuId:this.data.skuid,//膜ID
        sph:parameter.leftSph,//度数
        cyl:parameter.leftCyl,//散光
        add:parameter.leftAdd,//下加光add
        prodCount:this.data.prodNum,//数量
        zw:formData.axisLeft,//轴位,
        tj:"", //瞳距
        jjtd:formData.jjpLength,//渐进通道
        price:this.data.skuObj.price,//单价
      },
      right:{
        prodId:this.data.prodId,//产品id
        skuId:this.data.skuid,
        sph:parameter.rightSph,//度数
        cyl:parameter.leftCyl,//散光
        add:parameter.rightCyl,//下加光add
        prodCount:this.data.prodNum,//数量
        zw:formData.axisRight,//轴位,
        tj:"", //瞳距
        jjtd:formData.jjpLength,//渐进通道
        price:this.data.skuObj.price,//单价
      },
      tsjg:this.data.tsjgValue //特殊加工
    }
    orderApi.orderAdd(data).then((res)=>{
      console.log("--orderAdd--xx-->",res)
      let orderId = res
      wx.navigateTo({
        url: '../pay/pay?ordeId='+orderId
      })
    })
  
  },

  //售后
  afterSaleBtn() {
    if(this.data.threeMonthFlag) {
    let str = '此订单已超过三个月,请联系客服处理!'
    wx.showToast({
      title: str,
      icon: "none",
      duration: 800
    })
      return
    }
    wx.navigateTo({
      url: '../afterSale/afterSale?id='+this.data.orderId
    })
  },
 
  
 
})